//
//  FindTableViewCell.m
//  SugarPile
//
//  Created by Charlie. on 16/1/23.
//  Copyright © 2016年 www.lanou39.蓝鸥科技. All rights reserved.
//

#import "FindTableViewCell.h"
#import "LCPrefixHeader.pch"
#import "FindModel.h"
#import "GroupCollectionViewCell.h"
#import "TaobaoWebViewController.h"
@interface FindTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UICollectionView *findCollect;/**<嵌套collect*/
@property (nonatomic, retain) UICollectionViewFlowLayout *layout;/**<lyout*/
@end
@implementation FindTableViewCell

-(void)dealloc
{
    [_findCollect release];
    [_layout release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        // lyout
        self.layout = [[UICollectionViewFlowLayout alloc] init];
        [self.layout release];
        // collection
        self.findCollect = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 80 * H) collectionViewLayout:_layout];
        self.findCollect.backgroundColor = [UIColor floralWhite];
        [self.contentView addSubview:_findCollect];
        [self.findCollect release];
    }
    return self;
}
-(void)setFindArr:(NSMutableArray *)findArr
{
    if (_findArr != findArr) {
        [_findArr release];
        _findArr = [findArr retain];
//        self.arr = _findArr;
        // cell 大小
        self.layout.itemSize = CGSizeMake( WIDTH / 4 , 20 * H);
        // cell 间距 行 列
        _layout.minimumInteritemSpacing = 20 * H;
        _layout.minimumLineSpacing = 20 * W;
        // 边距
        _layout.sectionInset = UIEdgeInsetsMake(10 * W, WIDTH / 8, 10 * W, WIDTH / 8);
        
        self.findCollect.delegate = self;
        self.findCollect.dataSource = self;
//        _findCollect.collectionViewLayout = _lyout;
//        _findCollect.frame = CGRectMake(0, 0, 375, 40);
        [self.contentView addSubview:_findCollect];
        [_findCollect registerClass:[GroupCollectionViewCell class] forCellWithReuseIdentifier:@"findCell"];
    }
}
// collection方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    // cell个数
    return _findArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    GroupCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"findCell" forIndexPath:indexPath];
//    cell.backgroundColor = [UIColor blackColor];
    
    // 从Findvc 传值 进行对cell赋值
        FindModel *m = _findArr[indexPath.item];
        cell.name.text = m.name;
        
  
    return cell;
}
// 在collection 点击方法里实现协议传值方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    // 传值
    FindModel *m = _findArr[indexPath.item];
    NSString *temp = m.target;
    [self.delegate tianzhuanWithstring:temp];
    
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
